package com.alphacsp.theedge2012.ui.components.calendar;


import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.LayerDrawable;
import android.widget.Button;
import com.alphacsp.theedge2012.R;
import com.alphacsp.theedge2012.data.entities.Event;

/**
 * Created by IntelliJ IDEA.
 * User: Gilad
 * Date: 25/10/10
 * Time: 23:00
 */
public class CalendarEventButton extends Button {

    private final String eventId;
    private final Event event;

    public CalendarEventButton(Context context, Event event, String eventId) {
        super(context);

        this.event = event;
        this.eventId = eventId;

        LayerDrawable buttonDrawable = (LayerDrawable) context.getResources().getDrawable(R.drawable.calender_event);
        buttonDrawable.getDrawable(0).setColorFilter(event.getTrackColor(), PorterDuff.Mode.SRC_ATOP);
        buttonDrawable.getDrawable(1).setAlpha(255);
        String name = event.getName();
        if (name.length() > 40) {
            name = name.trim();
            name = name.substring(0, name.lastIndexOf(" "));
            name = name + " ...";
        }
        setText(name);
        setTextColor(Color.WHITE);

        setBackgroundDrawable(buttonDrawable);
        setPadding(4, 3, 4, 3);


    }

    public Event getEvent() {
        return event;
    }

    public String getEventId() {
        return eventId;
    }
}
